var talk = new Talk();

specialAnchorIds = $("#specialAnchorIds").val()
privateChatUploadApi = $("#privateChatUploadApi").val()

layui.define(["table", "form", "admin"], function (exports) {
    var $ = layui.$,
        form = layui.form;
    //输入框监听事件
    talk.elem.write.on({
        keydown: function (ev) {
            var e = ev || window.event;
            if (e.keyCode == 13 && !(e.shiftKey) && !(e.ctrlKey) && !(e.metaKey)) {
                e.preventDefault();
                talk.send.text();
            }
            // textarea输入框换行
            if (e.ctrlKey && e.keyCode == 13) {
                talk.elem.write.val(talk.elem.write.val() + "\n")
            }
        },
    });

    $('body').on('click', ".chat-tab-btn", function () {
        $('.chat-tab-btn-active').removeClass('chat-tab-btn-active')
        $(this).addClass('chat-tab-btn-active')
        var anchorid = $(this).attr("data-topanchorid")

        getSessionList(anchorid)
        console.log("specialAnchorIds:specialAnchorIds", specialAnchorIds)
    })

    // 左侧会话列表点击切换
    $('body').on('click', 'dd', function () {
        talk.user.id = $(this).attr("data-userid");
        talk.session_id = $(this).attr("data-sessionid");
        var anchorid = $(this).attr("data-anchorid")
        curAnchorName = $(this).attr("data-anchorname")
        curChannel    = $(this).attr("data-channel")
        rsUserName = $(this).attr("data-rsUserName")
        ban = $(this).attr("data-ban")
        curAnchorid = anchorid
        curSessionId = talk.session_id
        $('.chatList dd').removeClass('active')
        $(this).addClass('active')
        $("#ban-btn").css("display", "block");
        user_id = talk.user.id;
        session_id = talk.session_id;
        var ban_btn = "禁言"
        if (ban == 1) {
            ban_btn = "解除禁言"
        }
        $("#ban-btn").html(ban_btn)
        talk.init();
    })

    // 禁言时间选择
    form.on('select(band_time)', function (data) {
        layer.load()
        $.ajax({
            url: '/admin/privatechat/band_user',
            type: 'post',
            dataType: 'json',
            data: { session_id: talk.session_id, time: data.value },
            success: function (res) {
                if (res.code == 0) {
                    return layer.msg(res.msg, { icon: 1 });
                }
                return layer.msg(res.msg);
            },
            error: function (err) {
                layer.msg('系统异常,请稍后再试!');
            },
            complete: function () {
                layer.closeAll('loading');
            }
        });

    });


    //发送消息
    form.on('submit(expert-edit)', function (obj) {
        talk.send.text();
    });

    exports("privatechat", {});
});
